package cn.ddy;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.Map;

/**
 * @author ddy
 * @create 2020-08-19 09:14:00
 */
@ControllerAdvice //用在类上，配合下面的注解，用于定义全局异常
public class ErrorController {
    @ExceptionHandler(ArithmeticException.class) //单独使用的话，只能用于当前Controller，局部异常
    public ModelAndView dealExceptionHandler(Exception e)
    {
        System.out.println("******Exception msg is: "+e.getMessage());
        ModelAndView mv = new ModelAndView();
        mv.addObject("myexception", e);
        mv.setViewName("error");
        return mv;
    }
}
